import java.util.*;

public class MapTraversalExample {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("key1",1);
        map.put("key2",2);
        map.put("key3",3);
        map.put("key4",4);


        for(Map.Entry<String,Integer> entry:map.entrySet()){
            System.out.println("key:"+entry.getKey()+" value:"+entry.getValue());
        }
        Set<String> keys =map.keySet();
        for(String key:keys){
            System.out.println("key:"+key);
        }
        Collection<Integer> values=map.values();
        for(Integer value:values){
            System.out.println("value:"+value);
        }

        map.forEach((key,value)->System.out.println("key:"+key+" value:"+value));

        map.entrySet().stream().forEach(entry->System.out.println("key:"+entry.getKey()+" value:"+entry.getValue()));
    }
}
